package cn.edu.scnu.socialapp.controller;

import cn.edu.scnu.socialapp.service.ArticleService;
import cn.edu.scnu.socialapp.model.vo.Result;
import cn.edu.scnu.socialapp.model.vo.params.ArticleParams;
import cn.edu.scnu.socialapp.model.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 使用json进行交互
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页文章列表
     * @param pageParams
     * @return vo.Result
     */
    @PostMapping
    //Result是统一结果返回
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }


    @PostMapping("listArchives")
    public Result listArchives() {
        return articleService.listArchives();
    }


    @PostMapping("query/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }

    @DeleteMapping("delete/{id}")
    public Result deleteArticle(@PathVariable("id") Long articleId){
        return articleService.deleteArticleById(articleId);
    }

    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParams articleParams){
        return articleService.publish(articleParams);
    }


    @PostMapping("edit")
    public Result editArticle(@RequestBody ArticleParams articleParams) {
        return articleService.edit(articleParams);
    }

}
